home *** CD-ROM | disk | FTP | other *** search
- #include "ProgressCDEF Demo.h"
-
-
- /*******************************************************************************
-
- ••• main •••
-
- *******************************************************************************/
- main()
- {
- InitToolbox();
- InitScoreCard();
- MainEventLoop();
- DoQuit();
- }
-
-
- /*******************************************************************************
-
- ••• InitToolbox •••
-
- *******************************************************************************/
- void InitToolbox()
- {
- Handle menuBar;
- EventRecord event;
-
-
- gInBackground = false;
- gQuit = false;
-
- InitGraf( (Ptr) &qd.thePort);
- InitFonts();
- FlushEvents( everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NIL);
- InitResources();
- MaxApplZone();
-
-
- for ( count = 1; count <= 3; ++count) EventAvail(everyEvent, &event);
- SysEnvirons( curSysEnvVers, &gMac);
- if ( gMac.systemVersion < 0x0700) BadAlert(errWimpySystem);
-
- menuBar = GetNewMBar( 128);
- if (!menuBar) BadAlert(errCorrupt);
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu( GetMHandle(mApple), 'DRVR');
- DrawMenuBar();
-
- InitCursor();
- }
-
-
- /*******************************************************************************
-
- ••• MainEventLoop •••
-
- *******************************************************************************/
- void MainEventLoop( void )
- {
- Boolean gotEvent;
- EventRecord event;
-
- while (!gQuit)
- {
- gotEvent = WaitNextEvent( everyEvent, &event, 15, NIL);
- if (gotEvent) HandleEvent(&event);
- else DoIdle(&event);
- }
- }
-
-
- /*******************************************************************************
-
- ••• HandleEvent •••
-
- *******************************************************************************/
- void HandleEvent( EventRecord *event)
- {
- WindowPtr theWindow;
- short part = FindWindow( event->where, &theWindow);
-
- switch (event->what)
- {
- case mouseDown: HandleMouseDown(event); break;
- case keyDown:
- case autoKey: HandleKeyPress(event); break;
- case activateEvt: PrepareActivateEvent(event); break;
- case updateEvt: HandleUpdateEvent(event); break;
- case diskEvt: HandleDiskInsert(event); break;
- case osEvt:
- switch (( event->message >> 24) & 0x00FF)
- {
- case suspendResumeMessage:
- gInBackground = HandleOSEvent(event);
- break;
- }
- break;
- }
- }
-
-
- /*******************************************************************************
-
- ••• HandleDiskInsert •••
-
- *******************************************************************************/
- void HandleDiskInsert( EventRecord *event)
- {
- Point aPoint = { 100, 104};
-
- if ( HiWord( event->message) != noErr )
- {
- (void) DIBadMount( aPoint, event->message);
- }
- }
-
-
- /*******************************************************************************
-
- ••• HandleKeyPress •••
-
- *******************************************************************************/
- void HandleKeyPress( EventRecord *event)
- {
- char key = event->message & charCodeMask;
- if ( event->modifiers & cmdKey) HandleMenuCommand( MenuKey(key));
- }
-
-
- /*******************************************************************************
-
- ••• HandleMouseDown •••
-
- *******************************************************************************/
- void HandleMouseDown( EventRecord *event)
- {
- DialogPtr d;
- short i, part = FindWindow( event->where, &theWindow);
- Boolean dlgEvent;
-
-
- switch (part)
- {
- case inMenuBar: HandleMenuCommand( MenuSelect(event->where)); break;
- case inSysWindow:
- SystemClick( event, theWindow);
- break;
- case inDrag:
- if ( theWindow == FrontWindow())
- {
- DragWindow( theWindow, event->where, &qd.screenBits.bounds);
- }
- break;
- case inGoAway:
- if (TrackBox( theWindow, event->where, part)) DoQuit();
- break;
- case inContent:
- d = FrontWindow();
- dlgEvent = DialogSelect( event, &d, &i);
- if (dlgEvent) HandleDialogClick( d, i);
- break;
- }
- }
-
-
- /*******************************************************************************
-
- ••• HandleMenuCommand •••
-
- *******************************************************************************/
- void HandleMenuCommand( long menuResult)
- {
- Str255 daName;
- short menuID, menuItem;
-
-
- menuID = HiWord(menuResult);
- menuItem = LoWord(menuResult);
-
- switch (menuID)
- {
- case mApple:
- switch (menuItem)
- {
- case iAbout: break;
- default:
- GetItem( GetMHandle(mApple), menuItem, daName);
- (void) OpenDeskAcc(daName);
- break;
- }
- break;
-
- case mFile:
- gQuit = true;
- break;
- }
- HiliteMenu(0);
- }
-
-
- /*******************************************************************************
-
- ••• HandleDialogClick() 23/1/1994 at 16:30 •••
-
- *******************************************************************************/
- void HandleDialogClick( DialogPtr d, short i)
- {
- ControlRef pBar, button;
- Handle ih;
- Rect ir;
- long dl;
- short j, it, ctlItem, oldValue;
-
-
- if ( i > 2) return;
-
- GetDialogItem( d, i, &it, &ih, &ir); button = (ControlRef) ih;
- GetDialogItem( d, i + 2, &it, &ih, &ir); pBar = (ControlRef) ih;
- HiliteControl( button, 255);
- oldValue = GetDValue( d, i + 2);
-
- for ( j = 1; j <= 96; ++j) SetControlValue( pBar, oldValue + j);
-
- SetControlValue( pBar, oldValue);
- GetDialogItem( d, i, &it, &ih, &ir);
- HiliteControl( button, 0);
- }
-
-
- /*******************************************************************************
-
- ••• HandleUpdateEvent() 24/1/1994 at 18:26 •••
-
- *******************************************************************************/
- void HandleUpdateEvent( EventRecord *e)
- {
- DialogPtr d = (DialogPtr) e->message;
- short x;
-
- BeginUpdate(d);
- UpdateDialog( d, d->visRgn);
- EndUpdate(d);
- }
-
-
- /*******************************************************************************
-
- ••• DoQuit 26/1/1994 at 20:12 •••
-
- *******************************************************************************/
- void DoQuit()
- {
- DialogPtr d = FrontWindow();
-
- if (d) DisposeDialog(d);
- gQuit = true;
- }
-
-
- /*******************************************************************************
-
- ••• DoIdle 18/9/1995 at 18:56 •••
-
- *******************************************************************************/
- void DoIdle( EventRecord *event)
- {
- DialogPtr fd = FrontWindow();
- short i;
- Boolean result;
-
- if (fd) result = DialogSelect( event, &fd, &i);
- }
-
-
- /*******************************************************************************
-
- ••• PrepareActivateEvent 20/9/1995 at 17:32 •••
-
- *******************************************************************************/
- void PrepareActivateEvent( EventRecord *event)
- {
- WindowPtr w;
- Boolean activate;
-
- activate = ( event->modifiers & activeFlag) != 0;
- w = (WindowPtr) event->message;
- if (w) HandleActivateEvent( w, activate, event);
- }
-
-
- /*******************************************************************************
-
- ••• HandleActivateEvent 20/9/1995 at 12:48 •••
-
- *******************************************************************************/
- void HandleActivateEvent( WindowPtr w, Boolean activate, EventRecord *event)
- {
- short i;
- Boolean handled;
-
- SetPort(w);
- handled = DialogSelect( event, &w, &i);
- }